﻿#include <easyx.h>
#include <conio.h>
#include <ctime>
#include <string>
#include<vector>
#include <Windows.h>  // Windows 特有头文件
#include<iostream>
#include<random>
#include<cmath>
#pragma comment(lib,"MSIMG32.LIB")//透明动画用头文件
#pragma comment(lib,"Winmm.lib")
#pragma comment(lib,"MSIMG32.LIB")

using namespace std;

int score = 0;
double speed = 1.0;//gamespeed
const int G_Y = 600;      // 地面Y坐标（跳跃返回位置）
double GRAVITY = 1.0*60;    // 重力加速度/s
int up_hp=5;


void show_score() {
	TCHAR score_1[10] = L"score";
	wstring str = to_wstring(score);
	settextstyle(40, 0, L"微软雅黑");
	outtextxy(1200 / 2 - textwidth(score_1)/2, 20, score_1);
	outtextxy(1200 / 2 - textwidth(str.c_str())/2, 60, str.c_str());
}

IMAGE* cucumber_1 = new IMAGE;
IMAGE* cucumber_2 = new IMAGE;
IMAGE* cucumber_3 = new IMAGE;
IMAGE* cucumber_4 = new IMAGE;
IMAGE* cucumber_5 = new IMAGE;
IMAGE* cucumber_6 = new IMAGE;
IMAGE* cucumber_7 = new IMAGE;
IMAGE* cucumber_8 = new IMAGE;
IMAGE* cucumber_9 = new IMAGE;
IMAGE* cucumber_10 = new IMAGE;
IMAGE* cucumber_11 = new IMAGE;
vector<IMAGE*> cucumber = { cucumber_1,cucumber_2,cucumber_3,cucumber_4,cucumber_5,cucumber_6,
cucumber_7,cucumber_8,cucumber_9,cucumber_10,cucumber_11};//黄瓜

IMAGE* mu_1 = new IMAGE;
IMAGE* mu_2 = new IMAGE;
IMAGE* mu_3 = new IMAGE;
IMAGE* mu_4 = new IMAGE;
IMAGE* mu_5 = new IMAGE;
IMAGE* mu_6 = new IMAGE;
IMAGE* mu_7 = new IMAGE;
IMAGE* mu_8 = new IMAGE;
IMAGE* mu_9 = new IMAGE;
IMAGE* mu_10 = new IMAGE;
IMAGE* mu_11 = new IMAGE;
IMAGE* mu_12 = new IMAGE;
IMAGE* mu_13 = new IMAGE;
IMAGE* mu_14 = new IMAGE;
vector<IMAGE*> mu = {mu_1,mu_2,mu_3,mu_4,mu_5,mu_6,mu_7,mu_8,mu_9,mu_10,mu_11,mu_12,mu_13,mu_14 };//墨提斯

IMAGE* mu_jump_1 = new IMAGE;
IMAGE* mu_jump_2 = new IMAGE;
IMAGE* mu_jump_3 = new IMAGE;
IMAGE* mu_jump_4 = new IMAGE;
IMAGE* mu_jump_5 = new IMAGE;
IMAGE* mu_jump_6 = new IMAGE;
IMAGE* mu_jump_7 = new IMAGE;
IMAGE* mu_jump_8 = new IMAGE;
IMAGE* mu_jump_9 = new IMAGE;
IMAGE* mu_jump_10 = new IMAGE;
IMAGE* mu_jump_11= new IMAGE;
IMAGE* mu_jump_12 = new IMAGE;
IMAGE* mu_jump_13 = new IMAGE;
IMAGE* mu_jump_14 = new IMAGE;
IMAGE* mu_jump_15 = new IMAGE;
vector<IMAGE*>mu_jump = { mu_jump_1,mu_jump_2,mu_jump_3,mu_jump_4,mu_jump_5,mu_jump_6,mu_jump_7,mu_jump_8,
mu_jump_9,mu_jump_10,mu_jump_11,mu_jump_12,mu_jump_13,mu_jump_14};//墨提斯跳跃

IMAGE* uika_1=new IMAGE; 
vector<IMAGE*> uika = { uika_1 };//初华

IMAGE* soyo_1 = new IMAGE;
IMAGE* soyo_2 = new IMAGE;
IMAGE* soyo_3 = new IMAGE;
IMAGE* soyo_4 = new IMAGE;
IMAGE* soyo_5 = new IMAGE;
vector<IMAGE*> soyo = { soyo_1 ,soyo_2 ,soyo_3 ,soyo_4 ,soyo_5,soyo_4,soyo_3,soyo_2 };//素世

IMAGE* rana_1 = new IMAGE;
vector<IMAGE*> rana = { rana_1 };//乐奈

IMAGE* saki_1 = new IMAGE;
IMAGE* saki_2 = new IMAGE;
IMAGE* saki_3 = new IMAGE;
IMAGE* saki_4 = new IMAGE;
IMAGE* saki_5 = new IMAGE;
vector<IMAGE*> saki = { saki_1,saki_2,saki_3,saki_4,saki_5, saki_4, saki_3, saki_2 };//祥子

IMAGE* ground_1=new IMAGE; //地面

IMAGE* back_ground = new IMAGE; //背景
IMAGE* back_ground_2 = new IMAGE; //背景


IMAGE* ground_word_1=new IMAGE;  //地面文字

void loadimages() {
	//上方是动画
	loadimage(&(*cucumber_1), L"picture/cucumber/1.png");
	loadimage(&(*cucumber_2), L"picture/cucumber/2.png");
	loadimage(&(*cucumber_3), L"picture/cucumber/3.png");
	loadimage(&(*cucumber_4), L"picture/cucumber/4.png");
	loadimage(&(*cucumber_5), L"picture/cucumber/5.png");
	loadimage(&(*cucumber_6), L"picture/cucumber/6.png");
	loadimage(&(*cucumber_7), L"picture/cucumber/7.png");
	loadimage(&(*cucumber_8), L"picture/cucumber/8.png");
	loadimage(&(*cucumber_9), L"picture/cucumber/9.png");
	loadimage(&(*cucumber_10), L"picture/cucumber/10.png");
	loadimage(&(*cucumber_11), L"picture/cucumber/11.png");

	loadimage(&(*mu_1), L"picture/mortis/1.png");
	loadimage(&(*mu_2), L"picture/mortis/2.png");
	loadimage(&(*mu_3), L"picture/mortis/3.png");
	loadimage(&(*mu_4), L"picture/mortis/4.png");
	loadimage(&(*mu_5), L"picture/mortis/5.png");
	loadimage(&(*mu_6), L"picture/mortis/6.png");
	loadimage(&(*mu_7), L"picture/mortis/7.png");
	loadimage(&(*mu_8), L"picture/mortis/8.png");
	loadimage(&(*mu_9), L"picture/mortis/9.png");
	loadimage(&(*mu_10), L"picture/mortis/10.png");
	loadimage(&(*mu_11), L"picture/mortis/11.png");
	loadimage(&(*mu_12), L"picture/mortis/12.png");
	loadimage(&(*mu_13), L"picture/mortis/13.png");
	loadimage(&(*mu_14), L"picture/mortis/14.png");

	loadimage(&(*mu_jump_1), L"picture/mortis_jump/1.png");
	loadimage(&(*mu_jump_2), L"picture/mortis_jump/2.png");
	loadimage(&(*mu_jump_3), L"picture/mortis_jump/3.png");
	loadimage(&(*mu_jump_4), L"picture/mortis_jump/4.png");
	loadimage(&(*mu_jump_5), L"picture/mortis_jump/5.png");
	loadimage(&(*mu_jump_6), L"picture/mortis_jump/6.png");
	loadimage(&(*mu_jump_7), L"picture/mortis_jump/7.png");
	loadimage(&(*mu_jump_8), L"picture/mortis_jump/8.png");
	loadimage(&(*mu_jump_9), L"picture/mortis_jump/9.png");
	loadimage(&(*mu_jump_10), L"picture/mortis_jump/10.png");
	loadimage(&(*mu_jump_11), L"picture/mortis_jump/11.png");
	loadimage(&(*mu_jump_12), L"picture/mortis_jump/12.png");
	loadimage(&(*mu_jump_13), L"picture/mortis_jump/13.png");
	loadimage(&(*mu_jump_14), L"picture/mortis_jump/14.png");
	loadimage(&(*mu_jump_15), L"picture/mortis_jump/15.png");

	loadimage(&(*uika_1), L"picture/uika.png");

	loadimage(&(*soyo_1), L"picture/soyo/1.png");
	loadimage(&(*soyo_2), L"picture/soyo/2.png");
	loadimage(&(*soyo_3), L"picture/soyo/3.png");
	loadimage(&(*soyo_4), L"picture/soyo/4.png");
	loadimage(&(*soyo_5), L"picture/soyo/5.png");

	loadimage(&(*rana_1), L"picture/rana.png");

	loadimage(&(*saki_1), L"picture/saki/1.png");
	loadimage(&(*saki_2), L"picture/saki/2.png");
	loadimage(&(*saki_3), L"picture/saki/3.png");
	loadimage(&(*saki_4), L"picture/saki/4.png");
	loadimage(&(*saki_5), L"picture/saki/5.png");
	//下方是非动画
	loadimage(&(*ground_1), L"picture/ground.png");

	loadimage(&(*back_ground), L"picture/big_mu.png");
	loadimage(&(*back_ground_2), L"picture/big_mu_2.png");


	loadimage(&(*ground_word_1), L"picture/ground_word.png");
}


int number_0 = 0;
int number_1=0;
int weightedRandom1()//0,1,2
{
	static random_device rd;
	static mt19937 gen(rd());
	discrete_distribution<> d({ 4,4,2 });
	int num = d(gen);
	if (d(gen) == 0) {
		number_0++;
		if (number_0 == 3) {
			num = 2; number_0 = 0;
		}
	}
	if (d(gen) == 1 || d(gen) == 2) {
		number_1++;
		if (number_1 == 2) {
			num = 0; number_1 = 0;
	}
		}
	return num;
}

double r1 = 4, r2 = 1.5, r3 = 3, r4 = 1.5;
int weightedRandom2()
{
	static random_device rd;
	static mt19937 gen(rd());
	discrete_distribution<> d({ r1,r2,r3 ,r4});//saki,soyo,rana,uika
	int num = d(gen);
	return num+1;
}

int random_3()
{
	static minstd_rand gen1(random_device{}());
	return gen1()%2;//0 or 1
}
////////////////////////////////////////////////////////////////////////////
inline void drawimage(int x, int y, IMAGE *img) 
{
	int w = img->getwidth();
	int h = img->getheight();
	AlphaBlend(GetImageHDC(NULL), x, y, w, h,
		GetImageHDC(img), 0, 0, w, h, { AC_SRC_OVER,0,255,AC_SRC_ALPHA });
}//绘制透明图片
////////////////////////////////////////////////////////////////////////////

enum kind
{
	enum_cucu = -1,
	enum_mu=0,
	enum_saki,
	enum_soyo,
	enum_rana,
	enum_uika,
	enum_mu_jump
};

class Animation {
private:
	vector<IMAGE*> *frame_list=nullptr;
	wstring wstr;
	int num;
	int timer = 0;
	int i = 0;//帧索引
	int interval_ms = 0;
public:
	Animation(int num= 1, int interval = 500) 
	{
		interval_ms = interval;
		this->num = num;
	}
	~Animation() {};

	void set_animation(int num, int interval) 
	{
		interval_ms = interval;
		this->num = num;
	}

	void set_images(int i = 0) 
	{//⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐重要，设置图片
		switch (i) {
		case enum_cucu: frame_list = &cucumber; break;
		case enum_mu:frame_list = &mu; break;
		case enum_saki:frame_list = &saki; break;
		case enum_soyo:frame_list = &soyo; break;
		case enum_rana:frame_list = &rana; break;
		case enum_uika:frame_list = &uika; break;
		case enum_mu_jump:frame_list = &mu_jump; break;
		}
	}

	void play_Animation(int x, int y, double delta_ms = 1000.0 / 60) 
	{//delta_ms表示距上次调用play_Animation过去了多少ms
		timer += delta_ms;
		if (timer >= interval_ms) {
			i = (i + 1) % num;
			timer = 0;
		}
		drawimage(x, y, (*frame_list)[i]);
	}
};
////////////////////////////////////////////////////////////////////////////

class Mutsumi {
private:
	int hp;
	double x = 200;
	double y = G_Y - 90;//初始xy坐标
	double vy = 0;
	bool isJumping = false;
	bool is_leftmove = false;
	bool is_rightmove = false;
	bool is_running = true;
	Animation mu;
	Animation mu_jump;
public:
	//POINT center = { 0,0 };
	POINT left_top = { 0,0 };
	POINT right_bottom = { 0,0 };

	Mutsumi(int num = 14, int interval = 70){
		mu.set_animation(14, interval);
		mu.set_images(enum_mu);
		mu_jump.set_animation(14, 65);
		mu_jump.set_images(enum_mu_jump);
		hp = 5;
	};

	void release() 
	{
		//center.x = x + 27; center.y = y + 39;
		left_top.x = x + 19; left_top.y = y + 21;
		right_bottom.x = x + 19 + 35; right_bottom.y = y + 21 + 57;
		if (is_running == true) { mu.play_Animation(x, y, 1000 / 60); }
		else { mu_jump.play_Animation(x, y, 1000 / 60); }
		//setfillcolor(BLACK);
		//solidrectangle(left_top.x, left_top.y, right_bottom.x, right_bottom.y);
	}

	void reduce_hp(int num) 
	{
		hp -= num;
		if (hp >= up_hp) { hp = up_hp; };
		
	}
	int HP()const { return hp; }
	void Check_hp()
	{
		TCHAR s[20];
		TCHAR s1[10]=L"❤️";//❤️
		TCHAR s2[20];
		_stprintf_s(s, _T("now_hp: %d"), hp);	// 高版本 VC 推荐使用 _stprintf_s 函数
		_stprintf_s(s2, _T("now_hp_上限: %d"), up_hp);
		settextcolor(BLACK);
		settextstyle(20,0,L"微软雅黑");
		setbkmode(TRANSPARENT);
		outtextxy(20, 50, s);
		outtextxy(20, 30, s2);
		for (int i = 0; i < hp; i++) {
			outtextxy(20+i*20, 70, s1);
		}
	}

	bool isjumping() { return isJumping; }
	void turn_to_jump() 
	{
		isJumping = true;
		is_running = false;  
		vy = -27; 
	}
	void turn_to_leftmove(bool t = true) { is_leftmove = t; }
	void turn_to_rightmove(bool t = true) { is_rightmove = t; }

	void jump( ) 
	{
		// 跳跃物理模拟
		if (isJumping) {
			vy = vy + GRAVITY/60;    // 应用重力
			y += vy;          // 更新位置
			// 落地检测
			if (y > G_Y - 90) {
				y = G_Y - 90;  
				vy = 0;
				isJumping = false; // 重置跳跃状态
				is_running = true;
			}
		}
	}

	void leftmove(double delta) 
	{
		if (x > 0 and is_leftmove) { x -= 10*60*delta; }
	}

	void rightmove(double delta) 
	{
		if (x < 450 and is_rightmove) { x += 10*60*delta; }
	}

	void reverse(double delta)
	{
		if (!is_leftmove and !is_rightmove) {
			if (x < 200-1) { x += 10 / 2*60*delta; }
			else if (x > 200+1) { x -= 10 / 2*60*delta; }
			//else { x = 200; }
		}
	};

	void ProcessEvent() 
	{
		ExMessage msg;

		while (peekmessage(&msg))
		{
			if (msg.message == WM_KEYDOWN)
			{
				switch (msg.vkcode)
				{
				case VK_SPACE:	if (!isjumping())turn_to_jump();	break;
				case 'W':	if (!isjumping())turn_to_jump();	break;
				case 'A':turn_to_leftmove(true); break;
				case 'D':turn_to_rightmove(true); break;
				case 'S':GRAVITY = 1.0 * 60 * 1.8;
				}
			}
			else if (msg.message == WM_KEYUP)
			{
				switch (msg.vkcode)
				{
				case 'A':turn_to_leftmove(false); break;
				case 'D':turn_to_rightmove(false); break;
				case 'S':GRAVITY = 1.0 * 60  ;
				}
			}
		}
	}

	void move(double delta) 
	{
		this->jump();
		this->leftmove(delta);
		this->rightmove(delta);
		this->reverse(delta);
	}

};
////////////////////////////////////////////////////////////////////////////
class Enemy {
private:
	double x = 1500;
	double y;
	int height = 98-10;
	int width = 93-10;
	double Enemy_speed = 1.5;
	bool is_alive = true;
	int kind = 1;
	double dx = 0;
	double dy = 0;
	int num;
	int help_counter = 0;
	Animation enemy;
	
public:
	Enemy(int kind = 1, int interval = 16,double e=1.5) {//c为敌人生成时间间隔
		switch (kind) {
		case enum_cucu:num = 11; break;
		case enum_saki:num = 8; break;
		case enum_soyo:num = 8; break;
		case enum_rana:num = 1; break;
		case enum_uika:num = 1; break;
		}
		if (kind == -1) { interval = 30; }
		enemy.set_animation(num, interval);
		enemy.set_images(kind);
		this->kind = kind;
		Enemy_speed = e;
	}
	~Enemy() {
	};

	int Kind() { return this->kind; }

	bool Check_hit_box(const Mutsumi& player) //AABB碰撞箱检测
	{
		// 玩家AABB
		int pLeft = player.left_top.x;
		int pRight = player.right_bottom.x;
		int pTop = player.left_top.y;
		int pBottom = player.right_bottom.y;

		// 敌人AABB
		int eLeft = x+10;
		int eRight = x+10 + width;
		int eTop = y+10;
		int eBottom = y+10 + height;
		
		

		return !(pRight < eLeft ||
			pLeft > eRight ||
			pBottom < eTop ||
			pTop > eBottom);
	}

	void hurted(Mutsumi& player) 
	{
		if (Check_hit_box(player)) 
		{
			switch (kind)
			{
			case enum_cucu: break;
			case enum_saki:
				mciSendString(_T("play hit from 0"), NULL, 0, NULL); 
				mciSendString(_T("play yada from 0"), NULL, 0, NULL);
				mciSendString(_T("play saki_cry from 0"), NULL, 0, NULL);
				break;
			case enum_soyo:mciSendString(_T("play nani from 0"), NULL, 0, NULL); break;
			case enum_rana:
				mciSendString(_T("play hit from 0"), NULL, 0, NULL); 
				mciSendString(_T("play yada from 0"), NULL, 0, NULL);
				mciSendString(_T("play mochabafei from 0"), NULL, 0, NULL);
				break;
			case enum_uika:
				mciSendString(_T("play hit from 0"), NULL, 0, NULL);
				if(x<=1050)mciSendString(_T("play sakijiang from 0"), NULL, 0, NULL);
				break;
			}
			/*if (kind != enum_cucu) {
				mciSendString(_T("play hit from 0"), NULL, 0, NULL);
			}*/
			is_alive = false;
			switch (kind) 
			{
			case enum_cucu:score+=1; return;
			case enum_saki:player.reduce_hp(1); return; 
			case enum_soyo:player.reduce_hp(-1); score += 2; return;
			case enum_rana:player.reduce_hp(1); return; 
			case enum_uika:player.reduce_hp(2); return; 
			}
			
		}
		if (x <= -100) { is_alive = false;  return; }
	}

	bool Check_alive() 
	{
		return is_alive;
	}

	enum floor {
		first_floor = 0,
		second_floor,
		third_floor
	};

	void Generate() 
	{
		int floor = weightedRandom1();
		if (kind != enum_rana) 
		{ 
			switch (floor)
			{
			case 0:y = G_Y - 2 * 65; break;
			case 1:y = G_Y - 3 * 80; break;
			case 2:y = G_Y - 4 * 95; break;
			}
		}
		else {
			if(score<=600){y = 100;}
			else {
				y = 100 + random_3() * 500;
			}
		}//rana
	}
	void move(double delta,const Mutsumi &mu) 
	{
		if (kind != enum_rana && kind!=enum_uika) 
		{
		x -= 10 * Enemy_speed*60*delta*speed;
		enemy.play_Animation(x, y, 16);
		//setfillcolor(BLACK);
		//fillrectangle(x+10, y+10, x+10 + width, y+10 + height);
		}
		else if(kind==enum_rana)
		{
			if (x >= 500) 
			{
				dx = mu.left_top.x - x;
				dy = mu.left_top.y - y;
				double length = sqrt(dx * dx + dy * dy);
				dx = dx / length;
				dy = dy / length;
				x += dx*10 * Enemy_speed * 60 * delta*speed;
				y += dy*10 * Enemy_speed * 60 * delta*speed;
				enemy.play_Animation(x, y, 16);
			}
			else 
			{
				x -= 10 * Enemy_speed * 60 * delta*speed;
				y += dy * 10 * Enemy_speed * 60 * delta*speed;
				enemy.play_Animation(x, y, 16);
			}
		}
		else {//kind=enum_uika;
			if (help_counter == 0) { x = 1100; help_counter++;  mciSendString(_T("play sakijiang from 0"), NULL, 0, NULL); }
			if (x >= 1000)
			{
				
				x -= 1 * 60 * delta;
				enemy.play_Animation(x, y, 16);
			}
			else 
			{
				x-=30* Enemy_speed * 60 * delta;
				enemy.play_Animation(x, y, 16);
			}
		}
	}
};

int help_enemy_counter = 40;
int help_TryGenerateEnemy_interval = help_enemy_counter / 2;
int help_interval_counter = 30;
void TryGenerateEnemy(vector<Enemy*>& enemy_list, int interval = help_TryGenerateEnemy_interval) {
	const int INTERVAL = interval;
	static int counter = 0;
	int k = weightedRandom2();
	//cout << k << endl;
	if (help_enemy_counter % help_interval_counter != 0) { k = -1; help_enemy_counter += help_TryGenerateEnemy_interval; }
	else { k = weightedRandom2(); help_enemy_counter = help_TryGenerateEnemy_interval;}
	if ((++counter) % (INTERVAL) == 0) {
		Enemy* enemy = new Enemy(k, 300, 1.5);
		enemy_list.push_back(enemy);
		enemy->Generate();
	}
}
void removeEnemy(vector<Enemy*>& enemy_list, Mutsumi& player) {
	for (Enemy* enemy : enemy_list) {
		enemy->hurted(player);
	}

	for (int i = 0; i < enemy_list.size(); i++) {
		Enemy* enemy = enemy_list[i];
		if (!enemy->Check_alive()) {
			swap(enemy_list[i], enemy_list.back());
			enemy_list.pop_back();
			delete enemy;
		}
	}
}
////////////////////////////////////////////////////////////////////////////

int stage = 0;
void set_stage()
{
	if (score >= 0 && score < 50) {//stage0
		if (stage == 0) { stage++; up_hp = 5;  speed = 0.8; help_enemy_counter = 40; r1 = 1; r2 = 0; r3 = 0; r4 = 0; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 50"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 50 && score < 100) {//stage1
		if (stage <= 1) { stage++; up_hp = 5;  speed = 0.85; help_enemy_counter = 40; r1 = 8; r2 = 2; r3 = 0; r4 = 0; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 100"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 100 && score < 200) {//stage2
		if (stage <= 2) { stage++; up_hp = 10;  speed = 0.9; help_enemy_counter = 40; r1 = 7; r2 = 2; r3 = 1; r4 = 0; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 300"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 200 && score < 300) {//stage3
		if (stage <= 3) { stage++; up_hp = 15;  speed = 0.95; help_enemy_counter = 40; r1 = 6; r2 = 1; r3 = 3; r4 = 0; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 300"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 300 && score < 400) {//stage4
		if (stage <= 4) { stage++; up_hp = 30;  speed = 1; help_enemy_counter = 40; r1 = 6; r2 = 1; r3 = 2; r4 = 1; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 600"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 400 && score < 600) {//stage5
		if (stage <= 5) { stage++; up_hp = 30;  speed = 1; help_enemy_counter = 40; r1 = 5; r2 = 1.5; r3 = 2; r4 = 1.5; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 600"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 600 && score < 900) {//stage6
		if (stage <= 6) { stage++; up_hp = 50;  speed = 1.1; help_enemy_counter = 30; r1 = 4.5; r2 = 2.5; r3 = 2; r4 = 1; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 900"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 900 && score < 1000) {//stage7
		if (stage <= 7) { stage++; up_hp = 50;  speed = 1.2; help_enemy_counter = 20; r1 = 0; r2 = 0; r3 = 10; r4 = 0; }
			TCHAR s[100];
			_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 1200"), score);
			settextstyle(25, 0, L"微软雅黑");
			outtextxy(20, 100, s);
			return;
	}
	if (score >= 1000 && score < 1100) {//stage8
		if (stage <= 8) { stage++; up_hp = 50;  speed = 1.2; help_enemy_counter = 30; r1 = 0; r2 = 0; r3 = 0; r4 = 10; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 1200"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}

	if (score >= 1100 && score < 1200) {//stage9
		if (stage <= 9) { stage++; up_hp = 50;  speed = 1.2; help_enemy_counter = 20; r1 = 0; r2 = 0; r3 = 5; r4 = 5; }
		TCHAR s[100];
		_stprintf_s(s, _T("距离下一个阶段还需要黄瓜: %d / 1200"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}


	if (score >= 1200) {//stage10
		if (stage <= 10) { stage++; up_hp = 50;  speed = 1.2; help_enemy_counter = 30; r1 = 0; r2 = 10; r3 = 0; r4 = 0; }
		TCHAR s[100];
		_stprintf_s(s, _T("目前没有下一阶段了，%d / soyolin ，接受soyo妈妈的馈赠吧！！！！！"), score);
		settextstyle(25, 0, L"微软雅黑");
		outtextxy(20, 100, s);
		return;
	}
}

////////////////////////////////////////////////////////////////////////////
int main()
{
	loadimages();
	Mutsumi mu(14, 70);
	vector<Enemy*> enemy_list;
	int x0 = 0;
	int x1 = 1288;

	mciSendString(_T("open music/Mortis_bgm.mp3 alias bgm"), NULL, 0, NULL);
	mciSendString(_T("play bgm repeat from 0"), NULL, 0, NULL);
	mciSendString(_T("open music/hit.mp3 alias hit"), NULL, 0, NULL);
	mciSendString(_T("open music/yada.mp3 alias yada"), NULL, 0, NULL);
	mciSendString(_T("open music/saki_cry.mp3 alias saki_cry"), NULL, 0, NULL);
	mciSendString(_T("open music/mochabafei.mp3 alias mochabafei"), NULL, 0, NULL);
	mciSendString(_T("open music/nani.mp3 alias nani"), NULL, 0, NULL);
	mciSendString(_T("open music/sakijiang.mp3 alias sakijiang"), NULL, 0, NULL);
	mciSendString(_T("open music/gameover.mp3 alias gameover"), NULL, 0, NULL);

	initgraph(1200, 800, EX_SHOWCONSOLE);
	setbkcolor(WHITE);
	
	cleardevice();

	double delta = 1 / 60;

	bool running = true;
	bool gamestart = false;
	ExMessage m;
	while (!gamestart) {
		settextcolor(BLACK);
		settextstyle(50, 0, L"微软雅黑");
		outtextxy(1200 / 2 - textwidth(L"🧙‍♀️坏心眼的蓝女巫♀️🧙‍") / 2, 50, L"🧙‍♀️坏心眼的蓝女巫♀️🧙‍");//🧙‍♀️🧙‍♀️
		settextstyle(32, 0, L"微软雅黑");
		outtextxy(200, 150, L"◾按 'W' 或 space 进行跳跃");
		outtextxy(200, 190, L"◾长按 'A' 或 'D' 进行左右移动, 松开回到固定位置");
		outtextxy(200, 230, L"◾长按 'S' 获得更大的重力加速度");
		outtextxy(200, 270, L"◾Mutsumi酱只有小黄瓜了，吃掉一个小黄瓜🥒加 1 分");
		outtextxy(200, 310, L"◾吃掉的黄瓜达一定数量进入下一阶段，目前一共设计最高阶段为1200分及以上");
		outtextxy(200, 350, L"◾血量上限❤️随阶段变化，血量为 0 时游戏结束");
		outtextxy(200, 390, L"◾sakiko是满脑子都只想着自己的坏心眼的蓝女巫，碰到减1❤️");
		outtextxy(200, 430, L"◾soyo是母亲，情人，朋友，同学，P友達，医生，黄瓜园丁~~~");
		outtextxy(218, 470, L"会给Mutsumi带来2个小黄瓜🥒，碰到加1❤️，soyo桑love!!!");
		outtextxy(200, 510, L"◾rana，是个猫猫，一定距离内会跟随Mutsumi飘来飘去，然后惯性移动，碰到减1❤️");
		outtextxy(200, 540, L"◾uika，姛中的真姛，出现时会缓慢移动1.5秒，然后极速向前冲刺，碰到减2❤️");
		outtextxy(200, 580, L"◾黑色的命令行窗口是游戏运行的基础，enter关不掉游戏时可以关窗口");

		settextstyle(50, 0, L"微软雅黑");
		outtextxy(1200/2-textwidth(L"按空格键开始游戏")/2, 620, L"按空格键开始游戏");
		while (peekmessage(&m)) {
			if (m.message == WM_KEYUP) { if (m.vkcode == VK_SPACE) { gamestart = true; } }
		}
	}
				
				
	BeginBatchDraw();//双缓冲区头--------------------------------------------
	while (running)
	{
		if (mu.HP() <= 0) { running = false; }//检查生命值以检查游戏进程
		
		DWORD fps_start = GetTickCount();
		// 计算时间差（秒）
		static DWORD last_time = 0;
		
		//睦头移动模块头------------------------------
		mu.ProcessEvent();
		mu.move(delta);
		//睦头移动模块尾------------------------------

	//敌人生成数据区头--------------------------------
		TryGenerateEnemy(enemy_list);
		removeEnemy(enemy_list, mu);
		//敌人生成数据区尾--------------------------------

	//背景数据区头--------------------------------------
		x0 -= 5 * speed; if (x0 <= -1200) { x0 = 1200; }
		x1 -= 5 * speed; if (x1 <= -1200) { x1 = 1200; }
		//背景数据区头--------------------------------------
	//绘图区头--------------------------------------
		cleardevice();
	
		

		drawimage(x0, G_Y - 25, ground_1);
		drawimage(x1, G_Y - 25, ground_1);
		drawimage(-250, G_Y - 80, ground_word_1);
		drawimage(x0, 0, back_ground);
		drawimage(x1, 0, back_ground_2);
		show_score();

		set_stage();
		mu.release();//绘制睦头
		mu.Check_hp();

		for (Enemy* enemy : enemy_list) {//绘制敌人
			enemy->move(delta,mu);
		}

		FlushBatchDraw();
		//绘图区尾--------------------------------------
	
		//帧率控制区
		DWORD current_time = GetTickCount();
		delta = (current_time - last_time) / 1000.0;
	
		if (delta > 0.016) { delta = 0.016; }
		else if (delta < 0.010) { delta = 0.010; }
		last_time = current_time;
		DWORD fps_end = GetTickCount();
		double fps_delta = (fps_end - fps_start)/2;;
		if (fps_delta <= 1000/60)
		{
			Sleep(1000 / 60 - fps_delta);
			//fps_delta = 1000/60;
		}
		else if (fps_delta >= 1000 / 80)
		{
			Sleep(1000 / 80 - fps_delta);
			fps_delta = 1000 / 80;
		}
	}
	EndBatchDraw();//双缓冲区尾---------------------------------------

	settextstyle(100, 0, L"微软雅黑");
	settextcolor(BLACK);
	outtextxy(1200 / 2 - textwidth(L"YOUR DEATH") / 2, 390, L"YOUR DEATH");

	mciSendString(_T("play gameover from 0"), NULL, 0, NULL);

	ExMessage m2;
	bool gameover=false;
	while (!gameover) {
		settextstyle(32, 0, L"微软雅黑");
		settextcolor(BLACK);
		outtextxy(1200 / 2 - textwidth(L"按Enter键结束游戏") / 2, 500, L"按Enter键结束游戏");
		while (peekmessage(&m2)) {
			if (m.message == WM_KEYUP) { if (m2.vkcode == VK_RETURN) { gameover = true; } }
		}
	}

	delete cucumber_1;
	delete cucumber_2;
	delete cucumber_3;
	delete cucumber_4;
	delete cucumber_5;
	delete cucumber_6;
	delete cucumber_7;
	delete cucumber_8;
	delete cucumber_9;
	delete cucumber_10;
	delete cucumber_11;


	delete mu_1;
	delete mu_2;
	delete mu_3;
	delete mu_4;
	delete mu_5;
	delete mu_6;
	delete mu_7;
	delete mu_8;
	delete mu_9;
	delete mu_10;
	delete mu_11;
	delete mu_12;
	delete mu_13;
	delete mu_14;

	delete mu_jump_1;
	delete mu_jump_2;
	delete mu_jump_3;
	delete mu_jump_4;
	delete mu_jump_5;
	delete mu_jump_6;
	delete mu_jump_7;
	delete mu_jump_8;
	delete mu_jump_9;
	delete mu_jump_10;
	delete mu_jump_11;
	delete mu_jump_12;
	delete mu_jump_13;
	delete mu_jump_14;
	delete mu_jump_15;

	delete uika_1;

	delete soyo_1;
	delete soyo_2;
	delete soyo_3;
	delete soyo_4;
	delete soyo_5;

	delete rana_1;

	delete saki_1;
	delete saki_2;
	delete saki_3;
	delete saki_4;
	delete saki_5;

	delete ground_1;

	delete back_ground;
	delete back_ground_2;

	delete ground_word_1;

	return 0;
}